{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
}}

<Hds::PageHeader class="has-top-margin-xl has-bottom-margin-m" as |PH|>
  <PH.Title>Raft Storage</PH.Title>
  <PH.Actions>
    <Hds::Dropdown as |dd|>
      <dd.ToggleButton @text="Snapshots" @color="secondary" />
      {{#if this.useServiceWorker}}
        <dd.Interactive
          @href="/v1/sys/storage/raft/snapshot"
          @isHrefExternal={{false}}
          {{on "click" (action "downloadViaServiceWorker")}}
        >Download</dd.Interactive>
      {{else}}
        <dd.Interactive {{on "click" (action "downloadSnapshot")}}>Download</dd.Interactive>
      {{/if}}
      <dd.Interactive @route="vault.cluster.storage-restore">Restore</dd.Interactive>
    </Hds::Dropdown>
  </PH.Actions>
</Hds::PageHeader>

<Hds::Table @caption="Raft servers">
  <:head as |H|>
    <H.Tr>
      <H.Th>Address</H.Th>
      <H.Th>Leader</H.Th>
      <H.Th>Voter</H.Th>
      <H.Th @align="right">Actions</H.Th>
    </H.Tr>
  </:head>
  <:body as |B|>
    {{#each @model as |server|}}
      <B.Tr data-raft-row>
        <B.Td>{{server.address}}</B.Td>
        <B.Td>{{#if server.leader}}
            <Hds::Badge @text="Yes" @type="outlined" @color="success" @icon="check-circle" />
          {{else}}
            <Hds::Badge @text="No" @type="outlined" @icon="x-square" />
          {{/if}}
        </B.Td>
        <B.Td>
          {{#if server.voter}}
            <Hds::Badge @text="Yes" @type="outlined" @color="success" @icon="check-circle" />
          {{else}}
            <Hds::Badge @text="No" @type="outlined" @icon="x-square" />
          {{/if}}
        </B.Td>
        <B.Td @align="right">
          <Hds::Dropdown @isInline={{true}} data-test-raft-actions as |dd|>
            <dd.ToggleIcon @icon="more-horizontal" @text="Raft server actions" @hasChevron={{false}} />
            <dd.Generic>
              <ConfirmAction
                @isInDropdown={{true}}
                @onConfirmAction={{action "removePeer" server}}
                @buttonText="Remove Peer"
                @confirmTitle="Remove {{server.nodeId}}?"
                @confirmMessage="This will remove the server from the raft cluster."
              />
            </dd.Generic>
          </Hds::Dropdown>
        </B.Td>
      </B.Tr>
    {{/each}}
  </:body>
</Hds::Table>